<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改页面</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" />
    <style>
        .layui-input {
            width: 220px;
        }
        .layui-form-item{
            margin-top: 5px;
            padding-bottom: 15px;
        }
    </style>
</head>
<body>
<form class="layui-form" id="form" lay-filter="upd">
    <input type="hidden" id="aid" name="aid">
    <div class="layui-form-item">
        <label class="layui-form-label">活动主题</label>
        <div class="layui-input-inline">
            <input type="text" name="asubject" id="asubject" required  lay-verify="required" placeholder="请输入活动主题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动内容</label>
        <div class="layui-input-inline">
            <input type="text" name="acontent" id="acontent" required  lay-verify="required" placeholder="请输入活动内容" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动地址</label>
        <div class="layui-input-inline">
            <input type="text" name="asite" id="asite" required  lay-verify="required" placeholder="请输入活动地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动花费</label>
        <div class="layui-input-inline">
            <input type="text" name="acost" id="acost" required  lay-verify="required" placeholder="请输入活动花费" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">组织者</label>
        <div class="layui-input-inline">
            <input type="text" name="aorganizer" id="aorganizer" required  lay-verify="required" placeholder="请输入组织者" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">举行时间</label>
        <div class="layui-input-inline">
            <input type="text" name="ataketime" id="ataketime" required  lay-verify="required" placeholder="请输入举行时间" autocomplete="off" class="layui-input">
        </div>
    </div>
</form>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
    //Demo
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        $().ready(function () {
            $.ajax({
                type: "post",
                url: "/ActivityServlet?method=queryOne",
                data: {"aid": getQueryString("aid")},
                dataType: "json",
                success: function (da) {
                    if (da.code == 0) {
                        // form.val("upd",da.data);
                        // console.log(da.data);
                        $.each(da.data,function (update,u) {
                            $('#aid').val(u.aid);
                            $("#asubject").val(u.asubject);
                            $('#acontent').val(u.acontent);
                            $('#asite').val(u.asite);
                            $('#acost').val(u.acost);
                            $('#aorganizer').val(u.aorganizer);
                            $('#ataketime').val(layui.util.toDateString(u.ataketime,'yyyy-MM-dd'));
                        })
                    } else {
                        layer.msg("查询数据失败！");
                    }
                }
            })
        })

        //监听提交
        form.on('submit(formDemo)', function(data) {
            //通过ajax提交后台
            $.ajax({
                url:'/ActivityServlet?method=update',
                type:"post",
                data:$('#form').serialize(),
                async:true,
                dataType: 'json',
                success:function (da) {
                    if (da.code===0){
                        layer.alert("修改成功！", function () {
                            parent.layer.closeAll();
                        });
                    }else {
                        layer.msg("修改失败！");
                    }
                }
            })
            return false;
        });
    })
    //获取传来的？后的 字段参数
    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
</script>
</body>
</html>